package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.QualityReq;
import com.sbj.dto.res.QualityRes;
import com.sbj.entity.Quality;
import com.sbj.service.QualityService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/20 09:55
 */
@RestController
@RequestMapping(value = "/quality")
@AllArgsConstructor
public class QualityController implements BaseCommonInterface<QualityReq, QualityRes> {

    private final QualityService qualityService;

    @Override
    public Result<String> save(@Valid QualityReq qualityReq) {
        qualityService.save(Convert.convert(Quality.class,qualityReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        qualityService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<QualityRes>> lists(QualityReq qualityReq) {

        return Result.successResult(qualityService.lists(qualityReq));
    }

    @Override
    public Result<QualityRes> findById(Integer id) {
        return Result.successResult(Convert.convert(QualityRes.class,qualityService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<QualityRes> list) {
        return null;
    }

    @GetMapping(value = "/findAll")
    public Result<List<QualityRes>> findAll() {
        return Result.successResult(Convert.toList(QualityRes.class,qualityService.list()));
    }
}
